<?php

namespace App\Containers\AppSection\Data\UI\API\Transformers;

use App\Containers\AppSection\Data\Models\Passport;
use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Item;

class PassportTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'first_photo', 'second_photo',
    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [

    ];

    public function transform(Passport $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'serial_number' => $t->serial_number,
            'issue_date' => $this->dateFormatter($t->issue_date),
            'department_code' => $t->department_code,
            'issued_by' => $t->issued_by,
            'created_at' => $this->dateFormatter($t->created_at),
            'updated_at' => $this->dateFormatter($t->updated_at),
            'readable_created_at' => $t->created_at->diffForHumans(),
            'readable_updated_at' => $t->updated_at->diffForHumans()
        ];
    }

    public function includeFirstPhoto(Passport $t): ?Item
    {
        // TODO убрать nullableItem
        return $this->nullableItem($t->first_photo, new FileTransformer);
    }

    public function includeSecondPhoto(Passport $t): ?Item
    {
        // TODO убрать nullableItem
        return $this->nullableItem($t->second_photo, new FileTransformer);
    }
}
